package com.yanghs.common.service.impl;

import com.yanghs.common.dao.HibernateDao;
import com.yanghs.common.entity.hbm.Authority;
import com.yanghs.common.entity.hbm.Userinfo;
import com.yanghs.common.service.IRoleService;
import org.mybatis.spring.SqlSessionTemplate;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * @author yanghs
 * @Description:
 * @date 2018/3/4 14:18
 */
public class RoleService implements IRoleService {

    @Resource(name = "sqlSessionTemplate")
    SqlSessionTemplate dao;
    @Resource(name = "hibernateDao")
    HibernateDao hibernateDao;
    public Collection<Authority> getRoleByUser(Userinfo userinfo) throws Exception {
        /*获取当前用户的权限信息*/
        Collection<Authority> authorityCollection =
                (Collection<Authority>) hibernateDao.find("select authority from Userinfo userinfo,UserRole  userrole,Roleinfo roleinfo,RoleAuthority  roleauthority, Authority  authority where userinfo.userid = userrole.userid and userrole.roleid = roleinfo.roleid and roleinfo.roleid = roleauthority.roleid and roleauthority.authorityid = authority.authorityid and userinfo.username = ?",userinfo.getUsername());
        return authorityCollection;
    }
}
